import { ApiProperty } from '@nestjs/swagger'
import {
  IsString,
  IsNotEmpty,
  IsOptional,
  IsNumberString,
  IsNumber,
  IsInt,
  Max,
  Min,
  IsArray
} from 'class-validator'

import {
  BaseDto,
  BaseErrorDto as BaseError,
  QueryPage
} from '../../apiProperty'
import { PostEntity, UserEntity } from '../../../entitys'

export class BaseErrorDto extends BaseError {
  @ApiProperty({ example: 400, type: Number })
  code: number
}

export class PostQueryPage extends QueryPage {
  @ApiProperty({ example: '1', type: String, required: false })
  @IsOptional()
  @IsNumberString({}, { message: 'category 参数不合法' })
  category: string
}

export class PostSearchQueryPage extends QueryPage {
  @ApiProperty({ example: '美女', type: String, required: false })
  @IsOptional()
  @IsString({ message: 'keyword 参数不合法' })
  keyword: string
}

export class QueryDto {
  @IsString({ message: '商品 id 必须是字符串' })
  @IsNotEmpty({ message: '商品 id 不能为空' })
  @ApiProperty({
    example: '5b36556ba836440a823d5f5b2fb88737',
    description: '商品 id'
  })
  id: string
}

export class PostDto {
  @ApiProperty({ example: 1, type: Number, required: false })
  @IsOptional()
  @IsNumber({}, { message: 'type 参数必须是数字' })
  @IsInt({ message: 'type 必须是整数' })
  @Max(5, { message: 'type 不合法' })
  @Min(0, { message: 'type 不合法' })
  type: number

  @ApiProperty({ example: '标题', type: String })
  @IsNotEmpty({ message: 'title 不能为空' })
  @IsString({ message: 'title 格式不正确' })
  title: string

  @ApiProperty({ example: '内容', type: String })
  @IsNotEmpty({ message: 'content 不能为空' })
  @IsString({ message: 'content 格式不正确' })
  content: string

  @ApiProperty({ example: [1, 2, 3], type: Array, required: false })
  @IsOptional()
  @IsArray({ message: 'category 必须是数组' })
  category: number[]

  @ApiProperty({ example: [], type: Array, required: false })
  @IsOptional()
  @IsArray({ message: 'cover 必须是数组' })
  cover: string[]
}

export class PostResponseDto extends BaseDto {
  @ApiProperty()
  data: PostEntity
  // data: UserEntity
}

export class ResponseDto extends BaseDto {
  @ApiProperty({ example: {} })
  data: {}
}

export class SetComment {
  @ApiProperty({ example: '标题', type: String })
  // @IsNotEmpty({ message: 'parentId 不能为空' })
  @IsString({ message: 'parentId 格式不正确' })
  parentId: string

  @ApiProperty({ example: '内容', type: String })
  @IsNotEmpty({ message: 'content 不能为空' })
  @IsString({ message: 'content 格式不正确' })
  content: string
}
